n, m = map(int, input().split())
board = [list(map(int, input().split())) for _ in range(n)]


def dfs(i, j):
    r = 0
    if i < 0 or i >= n: return 0
    if j < 0 or j >= m: return 0
    if board[i][j] != 1:
        return 0
    board[i][j] = 0
    r += dfs(i + 1, j)
    r += dfs(i - 1, j)
    r += dfs(i, j + 1)
    r += dfs(i, j - 1)
    return r + 1


max_area = 0
for x in range(n):
    for y in range(m):
        if board[x][y] == 1:
            max_area = max(dfs(x, y), max_area)
print(max_area)
